package main

import (
	"fmt"
	"sort"
)

//内建函数排序:4ms 16%,1.8MB 76%
func isStraight(nums []int) bool {
	sort.Ints(nums)
	loc := 0
	for i, v := range nums {
		if v != 0 {
			loc = i
			break
		}
	}
	return nums[4]-nums[loc] < 5 && !isRepeat(nums[loc:])
}

func isRepeat(nums []int) bool {
	for i := 1; i < len(nums); i++ {
		if nums[i] == nums[i-1] {
			return true
		}
	}
	return false
}

//set+遍历:0ms 100%,1.9Mb 13%
func isStraight1(nums []int) bool {
	min, max := 13, 0
	numsMap := make(map[int]bool)
	for _, v := range nums {
		if v != 0 {
			if !numsMap[v] {
				numsMap[v] = true
			} else {
				return false
			}
			if v < min {
				min = v
			}
			if v > max {
				max = v
			}
		}
	}
	return max-min < 5
}

func main() {
	fmt.Println(isStraight([]int{1, 4, 5, 0, 0}))
	fmt.Println(isStraight1([]int{1, 4, 5, 0, 0}))
}
